/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "enterprise_admin_extension_context.h"

#include "ability_business_error.h"
#include "edm_log.h"
#include "enterprise_device_mgr_proxy.h"
#include "napi_edm_error.h"

namespace OHOS {
namespace EDM {
EnterpriseAdminExtensionContext::EnterpriseAdminExtensionContext() {}

EnterpriseAdminExtensionContext::~EnterpriseAdminExtensionContext() {}

ErrCode EnterpriseAdminExtensionContext::StartAbilityByAdmin(const AppExecFwk::ElementName &admin,
    const AAFwk::Want &want, std::string& errMsg)
{
    auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
    ErrCode ret = proxy->StartAbilityByAdmin(admin, want, token_);
    if (ret != ERR_OK && !IsEDMErrCode(ret)) {
        auto abilityCode = AbilityRuntime::GetJsErrorCodeByNativeError(ret);
        errMsg = AbilityRuntime::GetErrorMsg(abilityCode);
        return EdmReturnErrCode::START_ABILITY_FAILED;
    }
    return ret;
}
}  // namespace EDM
}  // namespace OHOS